<template>
	<view class="container" :style="style">
		<view style="height: 40rpx;width: 100%;"></view>
		<view class="level-card" :style="cardBg">
			<view class="user-info">
				<image :src="levelInfo.avatar" class="image"></image>
				<view class="user-desc">
					<view class="text">{{ levelInfo.username }}</view>
					<view class="info">
						商城购物可享 <view class="num">{{ levelInfo.discount }}</view> 折
					</view>
				</view>
			</view>
			<view class="progress">
				<progress :percent="vipPercent" stroke-width="4" activeColor="#333" backgroundColor="#fff" style="margin-top: 40px;"/>
				<view style="font-size: 24rpx;margin-top: 10rpx;color:#282828">{{ levelInfo.experience }} / {{ levelInfo.next_experience }}</view>
			</view>
			<view class="vip-level">{{ levelInfo.title }}</view>
		</view>
		<view class="level-equity">
			<view class="title">
				<view class="titlel">我的成长特权</view>
				<view class="svip" @click="navToDetailPage('/pages/vip/index')">立即升级</view>
			</view>

			<view class="equity-list">
				<view class="equity-item">
					<image :src="img1" style="width: 90rpx;height: 90rpx;"></image>
					<span>购物折扣</span>
				</view>
				<view class="equity-item">
					<image :src="img2" style="width: 90rpx;height: 90rpx;"></image>
					<span>专属徽章</span>
				</view>
				<view class="equity-item">
					<image :src="img3" style="width: 90rpx;height: 90rpx;"></image>
					<span>经验累积</span>
				</view>
				<view class="equity-item">
					<image :src="img4" style="width: 90rpx;height: 90rpx;"></image>
					 <span>尊享客服</span>
				</view>
			</view>
		</view>
		<view class="level-up-title">快速升级技巧</view>
		<view class="level-up-list">
			<view class="up-item">
				<view class="info">
					<view class="title">
						签到
					</view>
					<view class="desc">每日签到可获得经验值</view>
				</view>
				<view class="info-btn" @click="navToDetailPage('/pages/integral/sign')">去签到</view>
			</view>
			<view class="up-item">
				<view class="info">
					<view class="title">
						购买商品 <view class="mask">+{{ upInfo.integral }}点经验/元</view>
					</view>
					<view class="desc">购买商品可获得对应的经验值</view>
				</view>
				<view class="info-btn" @click="navToDetailPage('/pages/index/index')">去购买</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		BASE_URL
	} from '@/config/app';
	
	export default {
		data() {
			return {
				style: "background-image: url('" + BASE_URL +  '/static/images/card-top-bg.png' + "'); background-size: 100%; background-repeat: no-repeat;",
				img1: BASE_URL + '/static/images/discount.png',
				img2: BASE_URL + '/static/images/vip.png',
				img3: BASE_URL + '/static/images/experience.png',
				img4: BASE_URL + '/static/images/king.png',
				cardBg: '',
				vipPercent: 0,
				levelInfo: {},
				upInfo: {}
			}
		},
		mounted() {
			this.getLevelInfo()
		},
		methods: {
			async getLevelInfo() {
				let res = await this.$api.user.level.get()
				this.upInfo = res.data.upInfo
				this.levelInfo = res.data.levelInfo
				
				this.vipPercent = (this.levelInfo.experience / this.levelInfo.next_experience) * 100
				this.cardBg = 'background: url("' + this.levelInfo.card_bg + '") center center no-repeat;background-size: cover;'
			},
			// 路由跳转
			navToDetailPage(path) {
				if (path == '/pages/index/index') {
					uni.switchTab({
						url: path
					})
				} else {
					uni.navigateTo({
						url: path
					})
				}
			},
		}
	}
</script>

<style lang='scss'>
	.uni-page-body {
		height: 100%;
	}
	.container {
		height: 100%;
		width: 100%;
		
		position: absolute;
		
		.level-card {
			width: 642rpx;
			height: 330rpx;
			margin: 0 auto;
			border-radius: 10rpx;
			
			.user-info {
				display: flex;
				align-items: center;
				height: 110rpx;
				padding-left: 20rpx;
				padding-top: 20rpx;
	
				.user-desc {
					display: flex;
					flex-direction: column;
					padding-left: 20rpx;
				}
				
				image {
					width: 90rpx;
					height: 90rpx;
					border: 3px solid hsla(0,0%,96.1%,.3);
					border-radius: 50%;
				}
				
				.text {
					flex: 1;
					min-width: 0;
					margin-right: 14rpx;
					margin-left: 14rpx;
					font-size: 30rpx;
					font-weight: 700;
					color: #666;
					margin-bottom: 10rpx;
				}
				
				.info {
					display: flex;
					font-size: 22rpx;
					color: #666;
					
					.num {
						font-size: 30rpx;
						font-style: italic;
						margin-top: -10rpx;
						margin-left: 10rpx;
						margin-right: 10rpx;
					}
				}
			}
			
			.progress {
				width: 320rpx;
				padding-left: 20rpx;
				padding-right: 20rpx;
			}
			
			.vip-level {
				position: absolute;
				top: 236rpx;
				left: 500rpx;
				width: 132rpx;
				height: 44rpx;
				font-weight: 700;
				font-size: 30rpx;
				line-height: 44rpx;
				text-align: center;
				color: #e1e6ed;
			}
		}
		
		.level-equity {
			width: 690rpx;
			height: 280rpx;
			background: #fff;
			margin: 0 auto;
			margin-top: 40rpx;
			border-radius: 10rpx;
			
			.title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 20rpx;
				
				.svip {
					height: 20px;
					padding-right: 18px;
					padding-left: 9px;
					border-radius: 10px;
					background: #333 url() calc(100% - 6px) 50%/9px 11px no-repeat;
					font-size: 12px;
					line-height: 20px;
					text-align: center;
					color: #ffdeb2;
				}
				
				.titlel {
					font-size: 32rpx;
					font-weight: 700;
					display: block;
				}
			}
		
			.equity-list {
				display: flex;
				margin-top: 10rpx;
				
				.equity-item {
					width: 172rpx;
					height: 200rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					
					span {
						font-size: 24rpx;
						font-weight: 500;
					}
				}
			}
		}
		
		.level-up-title {
			padding-top: 19px;
			padding-bottom: 16px;
			padding-left: 27px;
			font-weight: 700;
			font-size: 16px;
			color: #282828;
		}
		
		.level-up-list {
			display: flex;
			flex-direction: column;
			padding-right: 30rpx;
			padding-left: 30rpx;
			
			.up-item {
				height: 140rpx;
				padding-right: 24rpx;
				padding-left: 24rpx;
				border-radius: 4rpx;
				background-color: #fff;
				box-shadow: 0 4rpx 10rpx 0 hsla(0,0%,92.2%,.5);
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				
				.info {
					flex: 1;
					
					.title {
						padding-left: 18rpx;
						border-left: 4rpx solid #e8b869;
						font-weight: 700;
						font-size: 30rpx;
						line-height: 1.1;
						color: #282828;
						display: flex;
						align-items: center;
						
						.mask {
							margin-left: 20rpx;
							font-weight: 400;
							font-size: 24rpx;
							color: #c6985c;
						}
					}
					
					.desc {
						padding-left: 18rpx;
						margin-top: 18rpx;
						font-size: 22rpx;
						color: #999;
					}
				}
				
				.info-btn {
					width: 73px;
					height: 25px;
					border-radius: 12px;
					background: linear-gradient(-90deg,#e7b667,#ffeab5);
					font-size: 13px;
					line-height: 25px;
					text-align: center;
					color: #8a5f1e;
				}
			}
		}
	}
</style>